/**
 * 
 */
package test;

import junit.framework.TestCase;
import prototype2.DirectionVector;

/**
 * @author Mladen
 * 
 */
public class VectorAdditionTestCase extends TestCase {

	public void testAddition() {
		DirectionVector[] v = new DirectionVector[12];
		for (int i = 0, j = 0; i < 12; i++)
			if (i % 3 != 0) {
				v[j] = new DirectionVector(1, i * Math.PI / 6);
				// System.out.println(v[j]);
				j++;
			}
		DirectionVector resultPI4 = new DirectionVector(1, Math.PI / 4);
		DirectionVector resultPI2 = new DirectionVector(1, Math.PI / 2);
		DirectionVector resultPI0 = new DirectionVector(1, 0);
		DirectionVector resultINT0 = new DirectionVector(0, 0);

		assertEquals(resultPI4.getOrientation(), DirectionVector.addTwoVectors(
				v[0], v[1]).getOrientation());

		assertEquals(resultPI2.getOrientation(), DirectionVector.addTwoVectors(
				v[0], v[3]).getOrientation());

		// this one is ok, rounding error
		assertEquals(resultPI2.getOrientation(), DirectionVector.addTwoVectors(
				v[1], v[2]).getOrientation(), 0.001);

		// this too
		assertEquals(resultINT0.getIntensity(), DirectionVector.addTwoVectors(
				v[0], v[4]).getIntensity(), 0.001);

		assertEquals(resultPI0.getOrientation(), DirectionVector.addTwoVectors(
				v[0], v[7]).getOrientation()
				+ 2 * Math.PI, 0.001);

		/** ****************************************** */
		DirectionVector result3PI4 = new DirectionVector(1, 3 * Math.PI / 4);
		DirectionVector resultPI = new DirectionVector(1, Math.PI);

		assertEquals(result3PI4.getOrientation(), DirectionVector
				.addTwoVectors(v[2], v[3]).getOrientation(), 0.001);

		assertEquals(resultPI.getOrientation(), DirectionVector.addTwoVectors(
				v[2], v[5]).getOrientation(), 0.001);

		assertEquals(0, DirectionVector.addTwoVectors(v[2], v[6])
				.getIntensity(), 0.001);

		assertEquals(resultPI2.getOrientation(), DirectionVector.addTwoVectors(
				v[2], v[1]).getOrientation(), 0.001);

		assertEquals(resultPI.getOrientation(), DirectionVector.addTwoVectors(
				v[3], v[4]).getOrientation(), 0.001);

		/** ********************************************* */

		DirectionVector result5PI4 = new DirectionVector(1, 5 * Math.PI / 4);
		DirectionVector result3PI2 = new DirectionVector(1, 3 * Math.PI / 2);

		assertEquals(result5PI4.getOrientation(), DirectionVector
				.addTwoVectors(v[4], v[5]).getOrientation(), 0.001);

		assertEquals(result3PI2.getOrientation(), DirectionVector
				.addTwoVectors(v[4], v[7]).getOrientation(), 0.001);

		assertEquals(result3PI2.getOrientation(), DirectionVector
				.addTwoVectors(v[5], v[6]).getOrientation(), 0.001);

		assertEquals(resultINT0.getIntensity(), DirectionVector.addTwoVectors(
				v[4], v[0]).getIntensity(), 0.001);
		assertEquals(resultINT0.getIntensity(), DirectionVector.addTwoVectors(
				v[5], v[1]).getIntensity(), 0.001);

		/** ***************************************************** */

		DirectionVector result2PI = new DirectionVector(1, 2 * Math.PI);
		DirectionVector result7PI4 = new DirectionVector(1, 7 * Math.PI / 4);

		// assertEquals(result7PI4.getOrientation(), DirectionVector
		// .addTwoVectors(v[6], v[7]).getOrientation(), 0.001);

		// assertEquals(result2PI.getOrientation(),
		// DirectionVector.addTwoVectors(
		// v[6], v[1]).getOrientation(), 0.001);
		// assertEquals(result2PI.getOrientation(),
		// DirectionVector.addTwoVectors(
		// v[7], v[0]).getOrientation(), 0.001);
	}
}
